<html>
<head>
    <title>YUI Test Example</title>
    <link type="text/css" rel="stylesheet" href="../build/logger/assets/logger.css" />     
    <link type="text/css" rel="stylesheet" href="../build/yuitest/assets/testlogger.css" />
    <script type="text/javascript" src="../build/yahoo/yahoo.js"></script>
    <script type="text/javascript" src="../build/dom/dom.js"></script>
    <script type="text/javascript" src="../build/event/event.js"></script>
    <script type="text/javascript" src="../build/logger/logger.js"></script>
    <script type="text/javascript" src="../build/yuitest/yuitest-beta.js"></script>
</head>
<body>
    <h1>YUI Test Example</h1>
    <h2>DOM Events</h2>
    <p>This example tests the browser for its support of DOM Level 2 events. This tests the
    availability of DOM event listener methods as well as the ability to simulate events.</p>
    <p><input type="button" value="Run Tests" id="btnRun" /></p>
    
    <script type="text/javascript">
    
        var testCase = new YAHOO.tool.TestCase({

            //the name of the test case - if not provided, one is automatically generated
            name: "DOM Event Tests",
                        
            //-------------------------------------------------------------------------
            // Basic tests - all method names must begin with "test"
            //-------------------------------------------------------------------------
            
            /*
             * Tests the browser to see if it supports DOM Level 2 Events, which include
             * the basic event listener methods as well as event simulation.
             */
            testEventsLevel2 : function () {
            
                //shortcut variables
                var Assert = YAHOO.util.Assert;
                
                //first check to see what is reports
                Assert.isTrue(document.implementation.hasFeature("Events", "2.0"), "Browser doesn't support Events 2.0.");
                
                //see if add/remove event listener methods are there
                Assert.isFunction(document.body.addEventListener, "Browser doesn't support addEventListener.");
                Assert.isFunction(document.body.removeEventListener, "Browser doesn't support removeEventListener.");
                Assert.isFunction(document.body.dispatchEvent, "Browser doesn't support dispatchEvent.");
                
                //see if you can create an event
                var event = document.createEvent("Events");
                
                //interrogate the object
                Assert.isObject(event, "Event should be an object.");
                Assert.isFunction(event.initEvent, "Event should have an initEvent() method.");
                Assert.isFunction(event.preventDefault, "Event should have an preventDefault() method.");
                Assert.isFunction(event.stopPropagation, "Event should have an stopPropagation() method.");
                
                //initialize it and continue
                event.initEvent("click", true, true);
                Assert.isTrue(event.bubbles, "Event should have a bubbles property.");
                Assert.isTrue(event.cancelable, "Event should have a cancelable property.");
                Assert.isNotUndefined(event.currentTarget, "Event should have a currentTarget property.");
                Assert.isNotUndefined(event.target, "Event should have a target property.");
                Assert.isNumber(event.eventPhase, "Event should have an eventPhase property.");
                Assert.isNumber(event.timeStamp, "Event should have a timestamp property.");
                Assert.areEqual("click", event.type, "Event type should be 'click'.");
            },
            
            /*
             * Tests the browser to see if it supports DOM Level 2 UI Events.
             */
            testUIEventsLevel2 : function () {
            
                //shortcut variables
                var Assert = YAHOO.util.Assert;
                
                //first check to see what is reports
                Assert.isTrue(document.implementation.hasFeature("UIEvents", "2.0"), "Browser doesn't support UIEvents 2.0.");
                
                //see if you can create an event
                var event = document.createEvent("UIEvents");
                
                //interrogate the object
                Assert.isObject(event, "Event should be an object.");
                Assert.isFunction(event.initEvent, "Event should have an initEvent() method.");
                Assert.isFunction(event.initUIEvent, "Event should have an initUIEvent() method.");
                Assert.isFunction(event.preventDefault, "Event should have an preventDefault() method.");
                Assert.isFunction(event.stopPropagation, "Event should have an stopPropagation() method.");
                
                //initialize it and continue
                event.initUIEvent("click", true, true, window, 0);
                Assert.isTrue(event.bubbles, "Event should have a bubbles property.");
                Assert.isTrue(event.cancelable, "Event should have a cancelable property.");
                Assert.isNotUndefined(event.currentTarget, "Event should have a currentTarget property.");
                Assert.isNotUndefined(event.target, "Event should have a target property.");
                Assert.isNumber(event.eventPhase, "Event should have an eventPhase property.");
                Assert.isNumber(event.timeStamp, "Event should have a timestamp property.");
                Assert.areEqual(window, event.view, "Event should have a view property.");
                Assert.areEqual(0, event.detail, "Event should have a detail property.");
                Assert.areEqual("click", event.type, "Event type should be 'click'.");
            },
            
            /*
             * Tests the browser to see if it supports DOM Level 2 Mouse Events.
             */
            testMouseEventsLevel2 : function () {
            
                //shortcut variables
                var Assert = YAHOO.util.Assert;
                
                //first check to see what is reports
                Assert.isTrue(document.implementation.hasFeature("MouseEvents", "2.0"), "Browser doesn't support MouseEvents 2.0.");
                
                //see if you can create an event
                var event = document.createEvent("MouseEvents");
                
                //interrogate the object
                Assert.isObject(event, "Event should be an object.");
                Assert.isFunction(event.initEvent, "Event should have an initEvent() method.");
                Assert.isFunction(event.initUIEvent, "Event should have an initUIEvent() method.");
                Assert.isFunction(event.initMouseEvent, "Event should have an initMouseEvent() method.");
                Assert.isFunction(event.preventDefault, "Event should have an preventDefault() method.");
                Assert.isFunction(event.stopPropagation, "Event should have an stopPropagation() method.");
                
                //initialize it and continue
                event.initMouseEvent("click", true, true, window, 0, 10, 20, 30, 40, true, true, true, true, 2, document.body);
                Assert.isTrue(event.bubbles, "Event should have a bubbles property.");
                Assert.isTrue(event.cancelable, "Event should have a cancelable property.");
                Assert.isNotUndefined(event.currentTarget, "Event should have a currentTarget property.");
                Assert.isNotUndefined(event.target, "Event should have a target property.");
                Assert.isNumber(event.eventPhase, "Event should have an eventPhase property.");
                Assert.isNumber(event.timeStamp, "Event should have a timestamp property.");
                Assert.areEqual(window, event.view, "Event should have a view property.");
                Assert.areEqual(0, event.detail, "Event should have a detail property.");
                Assert.areEqual("click", event.type, "Event type should be 'click'.");
                Assert.areEqual(10, event.screenX, "Event screenX should be 10.");
                Assert.areEqual(20, event.screenY, "Event screenY should be 20.");
                Assert.areEqual(30, event.clientX, "Event clientX should be 30.");
                Assert.areEqual(40, event.clientY, "Event clientY should be 40.");
                Assert.isTrue(event.ctrlKey, "Event ctrlKey should be true.");
                Assert.isTrue(event.shiftKey, "Event shiftKey should be true.");
                Assert.isTrue(event.altKey, "Event altKey should be true.");
                Assert.isTrue(event.metaKey, "Event metaKey should be true.");
                Assert.areEqual(2, event.button, "Event button should be 2.");
                Assert.areEqual(document.body, event.relatedTarget, "Event relatedTarget should be document.body.");
            },

             /*
             * Tests the browser to see if it supports DOM Level 3 Events, which include
             * the basic event listener methods as well as event simulation.
             */
            testEventsLevel3 : function () {
            
                //shortcut variables
                var Assert = YAHOO.util.Assert;
                
                //first check to see what is reports
                Assert.isTrue(document.implementation.hasFeature("Events", "3.0"), "Browser doesn't support Events 3.0.");
                
                //see if add/remove event listener methods are there
                Assert.isFunction(document.body.addEventListener, "Browser doesn't support addEventListener.");
                Assert.isFunction(document.body.removeEventListener, "Browser doesn't support removeEventListener.");
                Assert.isFunction(document.body.addEventListenerNS, "Browser doesn't support addEventListenerNS.");
                Assert.isFunction(document.body.removeEventListenerNS, "Browser doesn't support removeEventListenerNS.");
                Assert.isFunction(document.body.dispatchEvent, "Browser doesn't support dispatchEvent.");
                
                //see if you can create an event
                var event = document.createEvent("Events");
                
                //interrogate the object
                Assert.isObject(event, "Event should be an object.");
                Assert.isFunction(event.initEvent, "Event should have an initEvent() method.");
                Assert.isFunction(event.initEventNS, "Event should have an initEvent() method.");
                Assert.isFunction(event.preventDefault, "Event should have an preventDefault() method.");
                Assert.isFunction(event.stopPropagation, "Event should have an stopPropagation() method.");
                Assert.isFunction(event.stopImmediatePropagation, "Event should have an stopImmediatePropagation() method.");
                Assert.isString(event.namespaceURI, "Event should have a namespaceURI property.");
                Assert.isBoolean(event.defaultPrevented, "Event should have a defaultPrevented property.");
                
                //initialize it and continue
                event.initEventNS("http://www.yahoo.com/", "click", true, true);
                Assert.areEqual("http://www.yahoo.com/", event.namespaceURI, "Event namespaceURI should be http://www.yahoo.com/.");
                Assert.isTrue(event.bubbles, "Event should have a bubbles property.");
                Assert.isTrue(event.cancelable, "Event should have a cancelable property.");
                Assert.isNotUndefined(event.currentTarget, "Event should have a currentTarget property.");
                Assert.isNotUndefined(event.target, "Event should have a target property.");
                Assert.isNumber(event.eventPhase, "Event should have an eventPhase property.");
                Assert.isNumber(event.timeStamp, "Event should have a timestamp property.");
                Assert.areEqual("click", event.type, "Event type should be 'click'.");
            },
            
            /*
             * Tests the browser to see if it supports DOM Level 3 UI Events.
             */
            testUIEventsLevel3 : function () {
            
                //shortcut variables
                var Assert = YAHOO.util.Assert;
                
                //first check to see what is reports
                Assert.isTrue(document.implementation.hasFeature("UIEvents", "3.0"), "Browser doesn't support UIEvents 3.0.");
                
                //see if you can create an event
                var event = document.createEvent("UIEvent");
                
                //interrogate the object
                Assert.isObject(event, "Event should be an object.");
                Assert.isFunction(event.initEvent, "Event should have an initEvent() method.");
                Assert.isFunction(event.initEventNS, "Event should have an initEventNS() method.");
                Assert.isFunction(event.initUIEvent, "Event should have an initUIEvent() method.");
                Assert.isFunction(event.initUIEventNS, "Event should have an initUIEventNS() method.");
                Assert.isFunction(event.preventDefault, "Event should have an preventDefault() method.");
                Assert.isFunction(event.stopPropagation, "Event should have an stopPropagation() method.");
                Assert.isFunction(event.stopImmediatePropagation, "Event should have an stopImmediatePropagation() method.");
                Assert.isString(event.namespaceURI, "Event should have a namespaceURI property.");
                Assert.isBoolean(event.defaultPrevented, "Event should have a defaultPrevented property.");
                
                //initialize it and continue
                event.initUIEventNS("http://www.yahoo.com/", "click", true, true, window, 0);
                Assert.areEqual("http://www.yahoo.com/", event.namespaceURI, "Event namespaceURI should be http://www.yahoo.com/.");
                Assert.isTrue(event.bubbles, "Event should have a bubbles property.");
                Assert.isTrue(event.cancelable, "Event should have a cancelable property.");
                Assert.isNotUndefined(event.currentTarget, "Event should have a currentTarget property.");
                Assert.isNotUndefined(event.target, "Event should have a target property.");
                Assert.isNumber(event.eventPhase, "Event should have an eventPhase property.");
                Assert.isNumber(event.timeStamp, "Event should have a timestamp property.");
                Assert.areEqual(window, event.view, "Event should have a view property.");
                Assert.areEqual(0, event.detail, "Event should have a detail property.");
                Assert.areEqual("click", event.type, "Event type should be 'click'.");
            },            
            
            /*
             * Tests the browser to see if it supports DOM Level 3 Mouse Events..
             */
            testMouseEventsLevel3 : function () {
            
                //shortcut variables
                var Assert = YAHOO.util.Assert;
                
                //first check to see what is reports
                Assert.isTrue(document.implementation.hasFeature("MouseEvents", "3.0"), "Browser doesn't support MouseEvents 3.0.");
                
                //see if you can create an event
                var event = document.createEvent("MouseEvent");
                
                //interrogate the object
                Assert.isObject(event, "Event should be an object.");
                Assert.isFunction(event.initEvent, "Event should have an initEvent() method.");
                Assert.isFunction(event.initEventNS, "Event should have an initEvent() method.");
                Assert.isFunction(event.initUIEvent, "Event should have an initUIEvent() method.");
                Assert.isFunction(event.initUIEventNS, "Event should have an initUIEventNS() method.");
                Assert.isFunction(event.initMouseEvent, "Event should have an initMouseEvent() method.");
                Assert.isFunction(event.initMouseEventNS, "Event should have an initMouseEventNS() method.");
                Assert.isFunction(event.preventDefault, "Event should have an preventDefault() method.");
                Assert.isFunction(event.stopPropagation, "Event should have an stopPropagation() method.");
                Assert.isFunction(event.stopImmediatePropagation, "Event should have an stopImmediatePropagation() method.");
                Assert.isString(event.namespaceURI, "Event should have a namespaceURI property.");
                Assert.isBoolean(event.defaultPrevented, "Event should have a defaultPrevented property.");
                Assert.isFunction(event.getModifierState, "Event should have a getModifierState() method.");
                
                //initialize it and continue
                event.initMouseEventNS("http://www.yahoo.com/", "click", true, true, window, 0, 10, 20, 30, 40, true, true, true, true, 2, document.body);
                Assert.areEqual("http://www.yahoo.com/", event.namespaceURI, "Event namespaceURI should be http://www.yahoo.com/.");
                Assert.isTrue(event.bubbles, "Event should have a bubbles property.");
                Assert.isTrue(event.cancelable, "Event should have a cancelable property.");
                Assert.isNotUndefined(event.currentTarget, "Event should have a currentTarget property.");
                Assert.isNotUndefined(event.target, "Event should have a target property.");
                Assert.isNumber(event.eventPhase, "Event should have an eventPhase property.");
                Assert.isNumber(event.timeStamp, "Event should have a timestamp property.");
                Assert.areEqual(window, event.view, "Event should have a view property.");
                Assert.areEqual(0, event.detail, "Event should have a detail property.");
                Assert.areEqual("click", event.type, "Event type should be 'click'.");
                Assert.areEqual(10, event.screenX, "Event screenX should be 10.");
                Assert.areEqual(20, event.screenY, "Event screenY should be 20.");
                Assert.areEqual(30, event.clientX, "Event clientX should be 30.");
                Assert.areEqual(40, event.clientY, "Event clientY should be 40.");
                Assert.isTrue(event.ctrlKey, "Event ctrlKey should be true.");
                Assert.isTrue(event.shiftKey, "Event shiftKey should be true.");
                Assert.isTrue(event.altKey, "Event altKey should be true.");
                Assert.isTrue(event.metaKey, "Event metaKey should be true.");
                Assert.areEqual(2, event.button, "Event button should be 2.");
                Assert.areEqual(document.body, event.relatedTarget, "Event relatedTarget should be document.body.");
            },
            
            /*
             * Tests the browser to see if it supports DOM Level 3 Keyboard Events..
             */
            testKeyboardEventsLevel3 : function () {
            
                //shortcut variables
                var Assert = YAHOO.util.Assert;
                
                //first check to see what is reports
                Assert.isTrue(document.implementation.hasFeature("KeyboardEvents", "3.0"), "Browser doesn't support KeyboardEvents 3.0.");
                
                //see if you can create an event
                var event = document.createEvent("KeyboardEvent");
                
                //interrogate the object
                Assert.isObject(event, "Event should be an object.");
                Assert.isFunction(event.initEvent, "Event should have an initEvent() method.");
                Assert.isFunction(event.initEventNS, "Event should have an initEvent() method.");
                Assert.isFunction(event.initUIEvent, "Event should have an initUIEvent() method.");
                Assert.isFunction(event.initUIEventNS, "Event should have an initUIEventNS() method.");
                Assert.isFunction(event.initKeyboardEvent, "Event should have an initKeyboardEvent() method.");
                Assert.isFunction(event.initKeyboardEventNS, "Event should have an initKeyboardEventNS() method.");
                Assert.isFunction(event.preventDefault, "Event should have an preventDefault() method.");
                Assert.isFunction(event.stopPropagation, "Event should have an stopPropagation() method.");
                Assert.isFunction(event.stopImmediatePropagation, "Event should have an stopImmediatePropagation() method.");
                Assert.isString(event.namespaceURI, "Event should have a namespaceURI property.");
                Assert.isBoolean(event.defaultPrevented, "Event should have a defaultPrevented property.");
                Assert.isFunction(event.getModifierState, "Event should have a getModifierState() method.");
                
                //initialize it and continue
                event.initKeyboardEventNS("http://www.yahoo.com/", "keydown", true, true, window, "U+0041", 0, "Alt Control");
                Assert.areEqual("http://www.yahoo.com/", event.namespaceURI, "Event namespaceURI should be http://www.yahoo.com/.");
                Assert.isTrue(event.bubbles, "Event should have a bubbles property.");
                Assert.isTrue(event.cancelable, "Event should have a cancelable property.");
                Assert.isNotUndefined(event.currentTarget, "Event should have a currentTarget property.");
                Assert.isNotUndefined(event.target, "Event should have a target property.");
                Assert.isNumber(event.eventPhase, "Event should have an eventPhase property.");
                Assert.isNumber(event.timeStamp, "Event should have a timestamp property.");
                Assert.areEqual(window, event.view, "Event should have a view property.");
                Assert.areEqual(0, event.detail, "Event should have a detail property.");
                Assert.areEqual("keydown", event.type, "Event type should be 'click'.");
                Assert.areEqual("U+0041", event.keyIdentifier, "Event keyIdentifier should be U+0041.");
                Assert.areEqual(0, event.keyLocation, "Event keyLocation should be 0.");
                Assert.isTrue(event.getModifierState("Alt"), "Event modifier Alt should be true.");
                Assert.isTrue(event.getModifierState("Control"), "Event modifier Control should be true.");
                Assert.isFalse(event.getModifierState("Shift"), "Event modifier Shift should be false.");
            },
            
            /*
             * Tests the browser to see if it supports DOM Level 3 Text Events..
             */
            testTextEventsLevel3 : function () {
            
                //shortcut variables
                var Assert = YAHOO.util.Assert;
                
                //first check to see what is reports
                Assert.isTrue(document.implementation.hasFeature("TextEvents", "3.0"), "Browser doesn't support TextEvents 3.0.");
                
                //see if you can create an event
                var event = document.createEvent("TextEvent");
                
                //interrogate the object
                Assert.isObject(event, "Event should be an object.");
                Assert.isFunction(event.initEvent, "Event should have an initEvent() method.");
                Assert.isFunction(event.initEventNS, "Event should have an initEvent() method.");
                Assert.isFunction(event.initUIEvent, "Event should have an initUIEvent() method.");
                Assert.isFunction(event.initUIEventNS, "Event should have an initMouseEventNS() method.");
                Assert.isFunction(event.initTextEvent, "Event should have an initTextEvent() method.");
                Assert.isFunction(event.initTextEventNS, "Event should have an initTextEventNS() method.");
                Assert.isFunction(event.preventDefault, "Event should have an preventDefault() method.");
                Assert.isFunction(event.stopPropagation, "Event should have an stopPropagation() method.");
                Assert.isFunction(event.stopImmediatePropagation, "Event should have an stopImmediatePropagation() method.");
                Assert.isString(event.namespaceURI, "Event should have a namespaceURI property.");
                Assert.isBoolean(event.defaultPrevented, "Event should have a defaultPrevented property.");
                
                //initialize it and continue
                event.initTextEventNS("http://www.yahoo.com/", "textInput", true, true, window, "a");
                Assert.areEqual("http://www.yahoo.com/", event.namespaceURI, "Event namespaceURI should be http://www.yahoo.com/.");
                Assert.isTrue(event.bubbles, "Event should have a bubbles property.");
                Assert.isTrue(event.cancelable, "Event should have a cancelable property.");
                Assert.isNotUndefined(event.currentTarget, "Event should have a currentTarget property.");
                Assert.isNotUndefined(event.target, "Event should have a target property.");
                Assert.isNumber(event.eventPhase, "Event should have an eventPhase property.");
                Assert.isNumber(event.timeStamp, "Event should have a timestamp property.");
                Assert.areEqual(window, event.view, "Event should have a view property.");
                Assert.areEqual("a", event.data, "Event data should be 'a'.");
                Assert.areEqual("textInput", event.type, "Event type should be 'textInput'.");
            }                             
        });
        
        function runTests(){
            YAHOO.tool.TestRunner.run();
        }
    
        // YAHOO.util.Event.onDomReady(function (){ // need to wait for the frame to load
        YAHOO.util.Event.on(window, "load", function (){
            //create the logger
            var logger = new YAHOO.tool.TestLogger();
            
            //add the tests
            YAHOO.tool.TestRunner.add(testCase);
            
            //add event handler
            YAHOO.util.Event.addListener("btnRun", "click", runTests);
    
            runTests();
        });        
    
    </script>
        


</body>
</html>
